import {httpLogin} from '../../api/login'

import Cookies from 'js-cookie' 
export default {
    namespaced: 'login',
    state:{
        user:{},
        token:'',
    },
    mutations: {
       setUser(state,payload){
        Cookies.set('token', payload.data.token);
        state.user=payload.data;
        state.token=payload.data.token
       }
    },
    actions: {
        asyncLogin ({commit}, payload ) {
           return new Promise((resolve,reject)=>{
               httpLogin('/login',payload).then(res=>{
                 if(res.data.meta.status===200){
                     commit('setUser', res.data)
                 }
                  resolve(res)
               },(err)=>{
                  reject(err)
               })
           })
        }
    },
}